﻿//Sam Marshall

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace FacebookLoginButton.Models
{
    [DebuggerDisplay("Node {Name} (Connections = {_connections.Count}, Distance = {DistanceFromStart})")]
    internal class Node
    {
        public IList<NodeConnection> _connections;

        internal string Name { get; private set; }

        internal int DistanceFromStart { get; set; }

        internal Node Parent { get; set; }

        internal IEnumerable<NodeConnection> Connections
        {
            get { return _connections; }
        }

        internal Node(string name)
        {
            Name = name;
            Parent = null;
            _connections = new List<NodeConnection>();
        }

        internal void AddConnection(Node targetNode, bool twoway)
        {
            if (targetNode == null) throw new ArgumentNullException("targetNode");
            if (targetNode == this) throw new ArgumentException("Node may not connect to itself.");
            NodeConnection temp = new NodeConnection(targetNode);
            // if (_connections.Contains(temp) == false)
            {
                _connections.Add(temp);
                if (twoway == true)
                {
                    targetNode.AddConnection(this, false);
                }
            }
        }
    }
}
